<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" placeholder="请输入一个四位数字" />
    <button>点击判断</button>
  </body>
</html>
<script>
  var ipt = document.querySelector("input");
  var btn = document.querySelector("button");
  btn.onclick = function () {
    x1 = parseInt(ipt.value / 1000);
    x2 = parseInt(ipt.value / 100) % 10;
    x3 = parseInt(ipt.value / 10) % 10;
    x4 = ipt.value % 10;
    if (ipt.value.trim() !== "") {
      if (!isNaN(ipt.value)) {
        if (x1 == x4 && x2 == x3) {
          alert(ipt.value + "为对称数");
        } else {
          alert(ipt.value + "不是对称数");
        }
      } else {
        alert("请输入数字");
      }
    } else {
      alert("请输入内容");
    }
    // if (ipt.value.trim() == "") {
    //   alert("请输入内容");
    // } else if (x1 == x4 && x2 == x3) {
    //   alert(ipt.value + "为对称数");
    // } else {
    //   alert(ipt.value + "不是对称数");
    // }
  };
</script>
